<template>
    <div id="footer">
        <ul>
            <li v-for="(menu, index) in menus" :key="index">
                <router-link :to="menu.path" :class="[menu.isActive ? 'active' : '', menu.name === '首页' ? 'home' : '']">
                    {{ menu.name }}
                </router-link>
            </li>
        </ul>
    </div>
</template>

<script setup>
import { ref, watch } from 'vue';
import router from '@/router';
import menusData from '@/store/MenuData';

const menus = ref(menusData);
// console.log(menus.value);
//检测当前路由变化，更新菜单激活状态
watch(router.currentRoute, (newVal) => {
    menus.value = menus.value.map((item) => {
        // console.log(item);
        //如果当前路由与菜单项的path相同，则为激活菜单项，设置isActive为true
        if (item.path === newVal.path) {
            // console.log(item);
            item.isActive = true;
        } else {
            item.isActive = false;
        }
        return item;
    })
})
</script>

<style scoped lang="scss">
#footer {
    width: 100%;
    height: 70px;
    position: absolute;
    left: 50%;
    bottom: 0.521vw;
    transform: translateX(-50%);
    background: url('@/assets/uiResources/footer.png');
    background-size: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: all;

    ul {
        width: 28.5%;
        display: flex;
        align-items: center;
        justify-content: space-around;
        list-style: none;
        margin-top: 24px;

        .active {
            color: #ec9b02;
            font-size: 18px;
            font-weight: bold;
        }

        a {
            color: #fff;
            font-size: 18px;
            text-decoration: none;
            transition: color 0.3s ease;

            &:hover {
                color: #c5c5de;
            }
        }

        .home {
            display: inline-block;
            transform: translate(-2px, -8px);
        }


    }
}
</style>